import { Module } from '@nestjs/common';
import { ApiService } from './services/api.service';
import { ApiController } from './controllers/api.controller';
import { TypeOrmModule } from '@nestjs/typeorm';
import { ConfigModule, ConfigService } from '@nestjs/config';
import ApiConfig from './api.config';
import { WxLoginController } from './controllers/login.controller';
import { WxLoginService } from './services/wxLogin.services';
import { UserService } from './services/user.service';
import { CommonModule } from 'src/common/common.module';
import { User } from 'src/api/entities/user.entity';
import { JwtService } from '@nestjs/jwt';
import { UserController } from './controllers/user.controller';
import { GoodsService } from './services/goods.services';
import { GoodsController } from './controllers/goods.controller';
import { Goods } from './entities/goods.entity';
import { GoodsCategory } from './entities/goodsCategory.entity';
import { Order } from './entities/order.entity';
import { CommonDic } from './entities/commonDic.entity';
import { OrderController } from './controllers/order.controller';
import { OrderService } from './services/order.services';

@Module({
  controllers: [
    ApiController,
    WxLoginController,
    UserController,
    GoodsController,
    OrderController,
  ],
  providers: [
    ApiService,
    WxLoginService,
    UserService,
    JwtService,
    GoodsService,
    OrderService,
  ],

  imports: [
    ConfigModule.forRoot({
      isGlobal: true,
      cache: true,
      load: [ApiConfig],
    }),
    TypeOrmModule.forRootAsync({
      imports: [ConfigModule],
      inject: [ConfigService],
      useFactory: async (configService: ConfigService) => ({
        ...configService.get('api.mysql'),
      }),
    }),
    TypeOrmModule.forFeature([User, Goods, GoodsCategory, CommonDic, Order]),
    CommonModule,
  ],
})
export class ApiModule {}
